package com.dreambreeze.controller;

import com.dreambreeze.common.bean.ResultBean;
import com.dreambreeze.pojo.User;
import com.dreambreeze.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @description:用户控制层
 * @auther: dream breeze
 * @date: 2019/07/01 22:50
 */
@Controller
@Api(tags = "用户接口")
@RequestMapping("/user")
public class UserController {
    @Resource
    private UserService userService;

    @ApiOperation("测试接口")
    @GetMapping("/hello")
    @ResponseBody
    public String hello() {
        return "hello";
    }
    
    @ApiOperation("添加或修改用户")
    @PostMapping("/addOrUpdate")
    @ResponseBody
    public ResultBean addOrUpdate(HttpServletRequest request, @RequestBody User user) {
        if (user == null)
            return ResultBean.errorParam();
        return userService.addOrUpdate(user);
    }

    @ApiOperation("获取用户信息")
    @PostMapping("/getUser")
    @ResponseBody
    public ResultBean getUser(HttpServletRequest request, @RequestBody User user) {
        if (user == null)
            return ResultBean.errorParam();
        return userService.selectByUser(user);
    }
    
    @ApiOperation("删除用户")
    @PostMapping("/delete")
    @ResponseBody
    public ResultBean delete(HttpServletRequest request, @RequestBody User user) {
        if (user == null)
            return ResultBean.errorParam();
        return userService.delete(user);
    }
    
}
